<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="/css/elementUI.css">
    <script src="/js/vue.js"></script>
    <script src="/js/elementUI.js"></script>
    <script src="/js/axios.js"></script>
    <script src="/js/util.js"></script>
</head>
<body>

<div id="app">

    <el-dialog title="请登录" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="用户名" :label-width="formLabelWidth">
                <el-input v-model="form.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" :label-width="formLabelWidth">
                <el-input v-model="form.password" autocomplete="off"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="login">登录</el-button>
        </div>
    </el-dialog>

</div>
<script>
    new Vue({
        el:"#app",
        data:{

            //表单相关
            dialogFormVisible: true,
            form: {
                username:"",
                password:""
            },
            formLabelWidth: '120px',

            token:"",

        },
        methods:{
            login(){
                axios.post("/login/weblogin",this.form,{
                    headers: {
                        'token': this.token,
                    }
                }).then(res=>{
                    let result = res.data;
                    if(result.code==1){
                        this.$message.error(result.msg)
                    }else{
                        // console.log(result)
                        localStorage.setItem("user_token",result.data.token)
                        location.href = "test.html"
                    }
                })

            }

        },
        created(){
            let token = localStorage.getItem("user_token")
            if(token){
                this.token = token
            }

        }
    })
</script>

</body>
</html>